<style scoped>
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }

  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }

  /*.rj-cell {*/
  /*  display: inline-block;*/
  /*  font-size: 0;*/
  /*  padding: 5px 15px;*/
  /*}*/

  /*.rj-cell.max span {*/
  /*  font-size: 16px;*/
  /*  padding-right: 20px;*/
  /*}*/

  /*.rj-cell label {*/
  /*  color: #333;*/
  /*  font-size: 14px;*/
  /*}*/

  /*.rj-cell span {*/
  /*  padding-left: 5px;*/
  /*  font-size: 14px;*/
  /*  color: #333;*/
  /*}*/

  .rj-cell.note {
    width: 100%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .attachimg {
    /*width: 100%;*/
  }

  .tit label, .tit span {
    font-size: 16px;
  }

  .tit label {
    padding-right: 20px;
  }

  .weui-panel.weui-panel_access {
    padding-bottom: 10px;
  }

  /*.weui-panel__bd:not(.base) {*/
  /*  width: 98%;*/
  /*  padding: 0 1% 2px 1%;*/
  /*}*/

  .rj-cont-tit:not(.base) {
    border-radius: 5px;
  }

  .weui-cell {
    background: #fff;
  }

  .weui-cells__title {
    text-align: left;
    background: #eee;
  }

  .oitem {
    padding: 3px;
  }

  #acts span {
    font-size: 14px;
  }

  .weui-label {
    text-align: left;
  }

  .weui-media-box {
    text-align: left;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui_navbar_item {
    font-size: 14px;
  }
  .weui_navbar_item.weui_bar_item_on {
    color: #3cc51f;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .list {
    overflow: auto;
  }
  /*.rj-cell {*/
  /*  display: inline-block;*/
  /*  font-size: 0;*/
  /*  width: 49%;*/
  /*}*/
  /*.rj-cell.max span{*/
  /*  font-size: 16px;*/
  /*  !*padding-right: 20px;*!*/
  /*}*/
  /*.rj-cell label {*/
  /*  color: #333;*/
  /*  font-size: 14px;*/
  /*  width: 54%;*/
  /*  display: inline-block;*/
  /*  padding: 5px 3%;*/
  /*  text-align: right;*/
  /*}*/
  /*.rj-cell span {*/
  /*  font-size: 14px;*/
  /*  color: #333;*/
  /*  display: inline-block;*/
  /*  width: 40%;*/
  /*}*/
  /*!*.rj-cell {*!*/
  /*!*    display: inline-block;*!*/
  /*!*    font-size: 0;*!*/
  /*!*    padding: 5px 15px;*!*/
  /*!*}*!*/
  /*!*.rj-cell.max span{*!*/
  /*!*    font-size: 16px;*!*/
  /*!*    padding-right: 20px;*!*/
  /*!*}*!*/
  /*!*.rj-cell.minpad{*!*/
  /*!*    padding-right: 10px !important;*!*/
  /*!*}*!*/
  /*!*.rj-cell label {*!*/
  /*!*    color: #333;*!*/
  /*!*    font-size: 14px;*!*/
  /*!*}*!*/
  /*!*.rj-cell span {*!*/
  /*!*    padding-left: 5px;*!*/
  /*!*    font-size: 14px;*!*/
  /*!*    color: #333;*!*/
  /*!*}*!*/
  /*.rj-cell.note{*/
  /*  width: 100%;*/
  /*}*/
  /*.rj-cell.note label{*/
  /*  float: left;*/
  /*}*/
  /*.rj-cell.note span{*/
  /*  width: 80%;*/
  /*  display: inline-block;*/
  /*}*/
  .weui-cells {
    margin-top: 0;
  }
  .rj-wrap {
    background: #eee;
    overflow:auto;overflow-x: hidden
  }
  .rj-cont {
    background: #fff;
  }
  .weui-panel {
    background: #eee;
  }
  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }
  .weui-panel {
    margin-top: 0;
  }
  .demos-content-padded {
    padding: 15px;
  }
  .attachimg {
    width: 100%;
  }
  .tp-item {
    width: 32%;text-align: center;background: #fafafa;
    padding: 5px 2px;
    /*overflow: auto;*/
  }

  .rj-cell {
    display: inline-block;
    font-size: 0;
    padding: 5px 15px;
    min-width: 25%;
  }

  .rj-cell.max span {
    font-size: 16px;
    padding-right: 20px;
  }

  .rj-cell label {
    color: #333;
    font-size: 14px;
  }

  .rj-cell span {
    padding-left: 5px;
    font-size: 14px;
    color: #333;
  }

  .rj-cell.note {
    width: 100%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

</style>
<template>
  <div class="comon" style="background: #eee;height: 100%">
    <div
      style="height: 50px; line-height: 50px; background: #fff; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      质检详情
      <a href="javascript:" @click="goBack" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <!--    主表信息-->
    <div class="weui-panel weui-panel_access">
      <div class="weui-panel__bd">
        <div class="weui-form-preview billitem rj-cont-tit">
          <div style="display: flex; background: #fafafa;">
            <div class="rj-cell max tp-item">
              <span style="width: 100%;">{{order.code}}</span>
            </div>
            <div class="rj-cell max tp-item">
              <span style="width: 100%;">{{order.plantor}}</span>
            </div>
            <div class="rj-cell max tp-item">
              <span style="width: 100%;">{{order.carcode}}</span>
            </div>
          </div>
          <div class="rj-cell half max">
            <label>抽检包数：</label>
            <span>{{qaform.chkpknum}}</span>
          </div>
          <div class="rj-cell half max">
            <label>抽检重量：</label>
            <span>{{qaform.chkwght}} </span>
          </div>
          <div class="rj-cell half">
            <label>扣杂标准：</label>
            <span>{{order.isdiscountName}}</span>
          </div>
          <div class="rj-cell half max">
            <label>不合格重量：</label>
            <!--                  <span v-if="order.deducttype  == 2">{{qaform.unqualifiedchkweight}}</span>-->
            <!--                  <span v-if="order.deducttype  == 1">{{qaform.notokweight}}</span>-->
            <span>{{qaform.notokweight}}</span>
          </div>
          <div class="rj-cell half max">
            <label>合格重量：</label>
            <span>{{qaform.okweight}}</span>
          </div>
          <!--              <template v-if="order.deducttype == 2">-->
          <!--                <div class="rj-cell max">-->
          <!--                  <label>土杂重量：</label>-->
          <!--                  <span>{{qaform.soilchkweight}} </span>-->
          <!--                </div>-->
          <!--                <div class="rj-cell max">-->
          <!--                  <label>土杂率：</label>-->
          <!--                  <span>{{qaform.soilchkrate}} %</span>-->
          <!--                </div>-->
          <!--                <div class="rj-cell max">-->
          <!--                  <label>不合格率：</label>-->
          <!--                  <span>{{qaform.unqualifiedchkrate}} %</span>-->
          <!--                </div>-->
          <!--              </template>-->
          <div class="rj-cell half max" v-if="[1,2,3].includes(parseInt(order.isdiscount))">
            <label>扣杂率：</label>
            <span>{{qaform.deductrate}}%</span>
          </div>
          <div v-if="showAdd" class="rj-cell max" style="display: block; text-align: right;">
            <a href="#" id="addbtn" class="actbtn" @click="$router.push({name: 'AddQarecord', query: {id: id, guid: guid}})" style="font-size: 14px;margin-right: 10px;color:#1aad19;" >添加 &gt;&gt;</a>
          </div>
        </div>
      </div>
      <template v-if="records.length > 0">
        <div v-for="(record, index) in records">
          <div class="weui-panel__hd record" id="">第{{index + 1}}袋
            <template v-if="qaform && qaform.operatorid == userid">
              <i class="weui-icon-cancel actbtn" @click="delRecord(record.guid)" style="float: right;"></i>
              <i class="weui-icon-info-circle actbtn" @click="editRecord(record.guid)" style="float: right;font-size:22px;"></i>
            </template>
          </div>
          <div class="weui-form-preview billitem">
            <div class="rj-cell">
              <label>总重量：</label>
              <span>{{record.totalweight}}</span>
            </div>
            <div class="rj-cell">
              <label>合格重量：</label>
              <span>{{record.okweight}}</span>
            </div>
            <div class="rj-cell">
              <label>土杂重量：</label>
              <span>{{record.mixweight}}</span>
            </div>
            <div v-for="(qaitem, index) in qaitems" class="rj-cell" v-if="qaitem && qaitem.itemname">
              <label>{{qaitem.itemname}}：</label>
              <span>{{record['item'.concat(index + 1).concat('weight')]}}</span>
            </div>
          </div>
        </div>
      </template>
    </div>
    <div class="weui_btn_area" id="subm">
      <div class="demos-content-padded">
        <a href="javascript:;" class="weui-btn weui-btn_primary" @click="goBack">返回</a>
      </div>
    </div>
  </div>
</template>

<script>
  import SalesOperationLogs7 from '@/components/common/SalesOperationLogs7'
  import CommentBom from '@/components/common/CommentBom'

  export default {
    name: 'Qarecord',
    data() {
      return {
        flowid: 40,
        userid: localStorage.userGuid,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        id: '',
        guid: '',
        baseInfo: {},
        baseItems: [],
        qaform: [],
        qaFormImg: [],
        isReady: false,
        ticket: '',
        dianfen: '',
        order: '',
        qaform: '',
        records: [],
        qaitems: [],
        fromPath: '',
        permissions: []
      }
    },
    components: {
      SalesOperationLogs7,
      CommentBom
    },
    beforeRouteEnter(to, from, next) {
      next(vm => {
        vm.fromPath = from.fullPath;
        if (from.fullPath.indexOf('Qacheck') > -1 || from.fullPath.indexOf('ViewForder') > -1 || from.fullPath.indexOf('Examine40') > -1 || from.fullPath.indexOf('Confirm40') > -1) {
          console.log(222222222)
          sessionStorage.setItem('fromPath', from.fullPath);
          console.log(sessionStorage.getItem('fromPath'));
        }
      })
    },
    created() {
      //获取权限
      this.getPermission();
    },
    mounted() {
      this.id = this.$route.query.id;
      this.guid = this.$route.query.guid;
      this.getbaseInfo(this.id);
    },
    computed: {
      showAdd: function () {
        let hasAddPermis = this.permissions.find(item => item.permission == 20 && item.srguid == this.order.strguid);
        return this.order.status == 35 && hasAddPermis;
      }
    },
    methods: {
      getPermission: async function() {
        await this.axios({
          method: 'get',
          url: '/prod-api/getPermis',
        }).then((response) => {
          if (response.data.code == 200) {
            this.permissions = response.data.data;
          } else {
            this.toastError("获取用户权限失败");
          }

        })
      },
      goBack: function() {
        console.log("sessionStorage.getItem('fromPath')",  sessionStorage.getItem('fromPath'));
        this.fromPath = sessionStorage.getItem('fromPath');
        sessionStorage.setItem('fromPath', null);
        console.log('this.fromPath:', this.fromPath)
        this.$router.push({path: this.fromPath})
      },
      delRecord: function(id) {
        let that = this;
        $.confirm("确定要删除该质检记录？", function() {
          that.axios({
            method: 'post',
            url: `/prod-api/harvest/freightorder/delRecord`,
            params: {guid: id}
          }).then(response => {
            if (response.data.code == 200) {
              that.toastText('删除成功');
              setTimeout(() => {
                that.getbaseInfo(that.id);
              }, 1000)
            } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
              //不不设置提示
            } else {
              that.toastError('系统错误');
            }
          });
        }, function() {
        });
      },
      editRecord: function(recordId) {
        this.$router.push({name: 'EditQarecord', query: {id: this.id, guid: this.guid, recordId: recordId}});
      },
      packUnit: function(unit, currency) {
        return unit != undefined && unit != '' ? currency == 2 ? '美元/' + unit : '元/' + unit : '';
      },
      getbaseInfo: async function (id) {
        await this.axios({
          method: 'get',
          url: `/prod-api/harvest/freightorder/getQaDetail`,
          params: {id, id}
        }).then(response => {
          if (response.data.code == 200) {
            this.baseInfo = response.data;
            this.order = this.baseInfo.order || {};
            this.records = this.baseInfo.records || [];
            // this.records = [{
            //   guid: 22,
            //   foguid
            //     :
            //     "7577",
            //   item1weight
            //     :
            //     "30",
            //   item2weight
            //     :
            //     "10",
            //   okweight
            //     :
            //     "80",
            //   totalweight
            //     :
            //     "100"
            // }];
            this.qaform = this.baseInfo.qaform || '';
            this.qaitems = this.baseInfo.qaitems || [];
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError('系统错误');
          }
          this.isReady = true;
        });
      },
    }
  }
</script>
